import threading
from time import sleep
import queue
from threading import Lock
import random


def producer(q):
    for i in range(10):
        q.put(i)
        print('-----放入{}'.format(i))
        sleep(random.random())


def consumer(q):
    while True:
        i = q.get()
        print('-----得到{}'.format(i))
        sleep(random.random())


if __name__ == '__main__':
    q = queue.Queue(3)
    t1 = threading.Thread(target=producer, args=(q,))
    t2 = threading.Thread(target=consumer, args=(q,))

    t1.start()
    t2.start()

    t1.join()
    t2.join()
